package brad.zimmerman.dungeon.game;

import android.util.Log;

//Determines a certain object's position, and converts from map coordinates to canvas coordinates
public class ClassObjPosition {
	int tiles, width, height, constant;
	public int[] arrayFoSho;
	public ClassObjPosition(int tiles, int scale, int width, int height){
		this.tiles = tiles;
		this.width = width;
		this.height = height;
		int count = 0;
		this.constant = (this.width/(21));
		arrayFoSho = new int[this.tiles+1];
		for (@SuppressWarnings("unused") int gumballs: this.arrayFoSho){
    		this.arrayFoSho[count] = (count* (((20*width)/21)/tiles))+(this.width/(21));
    		count++;
    	}
	}
	public ClassObjPosition(int tiles, int scale, int width, int height, boolean zoomed){
		this.tiles = tiles;
		this.width = width;
		this.height = height;
		int count = 0;
		this.constant = (this.width/(21));
		arrayFoSho = new int[this.tiles+1];
		for (@SuppressWarnings("unused") int gumballs: this.arrayFoSho){
    		this.arrayFoSho[count] = (count* (((20*width)/21)/tiles))+(this.width/(21));
    		count++;
    	}
	}
	public boolean onMap(int X, int Y){
		if(X >= constant 
			&& Y >= constant
			&& (X < (tiles*constant)+constant)
			&& (Y < (tiles*constant)+constant)){
			return true;
		}
		return false;
	}
	public boolean onMap(int X, int Y,boolean zoomed){
		if(X >= constant/2 
			&& Y >= constant/2
			&& (X < 21*constant)
			&& (Y < 21*constant)){
			return true;
		}
		return false;
	}
	int findXBoard(int X, int Y){
		coorObjectFindScreen tempObjX = new coorObjectFindScreen(X, Y);
		return tempObjX.getX();
	}
	int findYBoard(int X, int Y){
		coorObjectFindScreen tempObjY = new coorObjectFindScreen(X, Y);
		return tempObjY.getY();
	}
	int findXScreen(int X, int Y){
		coorObjectFindBoard tempObjX = new coorObjectFindBoard(X, Y);
		return tempObjX.getX();
	}
	int findYScreen(int X, int Y){
		coorObjectFindBoard tempObjY = new coorObjectFindBoard(X, Y);
		return tempObjY.getY();
	}
	int returnXMatrix(int X, int Y){
		coorObjectFindBoard tempObj = new coorObjectFindBoard(X, Y);
		return tempObj.getXBoard();
	}
	int returnYMatrix(int X, int Y){
		coorObjectFindBoard tempObj = new coorObjectFindBoard(X, Y);
		return tempObj.getYBoard();
	}
	int returnMapIndex(int X, int Y, int[][] map){
		coorObjectFindBoard tempObj = new coorObjectFindBoard(X, Y);
		return map[tempObj.getXBoard()][tempObj.getYBoard()];
	}
	int returnMapIndex(int moveX, int moveY, int X, int Y, int[][] map){
		coorObjectFindBoard tempObj = new coorObjectFindBoard(X, Y);
		//System.out.println("Board Coords: " + tempObj.getXBoard()+ ":"+tempObj.getYBoard());
		//System.out.println("Map Coords: " + (moveX + tempObj.getXBoard())+ ":"+(moveY + tempObj.getYBoard()));
		return map[moveX + tempObj.getXBoard()][moveY + tempObj.getYBoard()];
	}
	//Converts a board position into a screen position
	class coorObjectFindScreen {
		int x;
		int y;
		coorObjectFindScreen(int objX, int objY){
			//Log.d("dungeons - objX",""+ Integer.toString(objX));
			//Log.d("dungeons - objX",""+ Integer.toString(objY));
			//Log.d("dungeons - arraylength",""+ Integer.toString(arrayFoSho.length));
			this.x = arrayFoSho[objX];
			this.y = arrayFoSho[objY];
		}
		int getX(){
			return x;
		}
		int getY(){
			return y;
		}
	}
	//Converts a screen position into a board position
	class coorObjectFindBoard {
		int x;
		int y;
		coorObjectFindBoard(int objX, int objY){
			this.x = objX;
			this.y = objY;
		}
		int getX(){
			int settingNumber = 0;
			for (int tiles: arrayFoSho){
            	if (x<=tiles){
            		return settingNumber;
            		}
            	settingNumber = tiles;
        	}
			return 0;
		}
		int getY(){
			int settingNumber = 0;
			for (int tiles: arrayFoSho){
            	if (y<=tiles){
            		return settingNumber;
            		}
            	settingNumber = tiles;
        	}
			return 0;
		}
		int getXBoard(){
			int count = 0;
			for (int tiles: arrayFoSho){
            	if (x<=tiles){
            		return count--;
            		}
            	count++;
        	}
			return 0;
		}
		int getYBoard(){
			int count = 0;
			for (int tiles: arrayFoSho){
            	if (y<=tiles){
            		return count--;
            		}
            	count++;
        	}
			return 0;
		}
	}
}
